-#
  Copyright 2008 Garth Williams

  This file is part of CommandPost.

  CommandPost is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  CommandPost is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with CommandPost.  If not, see <http://www.gnu.org/licenses/>.


%table
  %tr
    %td{:valign => 'top'}
      = error_messages_for :report_type
      .box-title Edit Report Type
      .box
        .float-right
          = link_to_remote '<img src="/images/delete.png"/>', :url => report_type_path(@report_type), :confirm => "Delete #{h(@report_type.name)}?", :update => :report_types, :method => :delete
        - remote_form_for(@report_type, :update => { :success => 'report_types', :failure => 'report_type' }) do |f|
          .input
            Name
            %br
            = f.text_field :name, :class => 'input_text'
          .input.align-right
            = f.submit "Update Type", :class => 'button'
      .box-title Create Permissions
      .box
        - for role in @roles
          .role{:id => "report_type_role_#{role.id}"}
            = check_box_tag "report_type_role_#{role.id}_check", 'checked', @report_type.roles.include?(role)
            %label{:for => "report_type_role_#{role.id}_check"}= h role.name
            = observe_field "report_type_role_#{role.id}_check", :url => { :controller => 'report_type_permissions', :action => 'update', :report_type_id => @report_type.id, :role_id => role.id }, :frequency => 0.5, :complete => visual_effect(:highlight, "report_type_role_#{role.id}"), :method => :post
        - if @roles.length == 0
          No roles found
      .box-title Stages
      .box
        - for stage in @report_type.stages
          .stage{:id => "stage_radio_#{stage.id}"}
            = radio_button_tag 'first_stage', stage.id, (@report_type.first_stage != nil && stage == @report_type.first_stage), :title => "Make #{stage.name} the first stage"
            = link_to_remote h(stage.name), :url => edit_report_type_stage_path(@report_type, stage), :update => :stage, :method => :get
            = observe_field "first_stage_#{stage.id}", :url => { :controller => 'report_types', :action => 'set_first', :id => @report_type.id, :stage_id => stage.id }, :frequency => 0.5, :update => { :failure => 'stage' }, :success => visual_effect(:highlight, "stage_radio_#{stage.id}"), :method => :post, :condition => "$('first_stage_#{stage.id}').checked"
        .align-right
          %br
          = link_to_remote 'New Stage', :url => new_report_type_stage_path(@report_type), :update => :stage, :method => :get
    %td{:valign => 'top'}
      %img#loading_stage{:src => '/images/loading.gif', :style => 'display: none;'}
      #stage
